package com.xmut.mall.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.xmut.mall.order.dto.OrderComplaintCommunicationDto;
import com.xmut.mall.order.myenum.CommunicationOwnerEnum;
import com.xmut.mall.order.utils.RespBean;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmut.mall.order.utils.PageUtils;
import com.xmut.mall.order.utils.Query;

import com.xmut.mall.order.dao.OrderComplaintCommunicationDao;
import com.xmut.mall.order.entity.OrderComplaintCommunicationEntity;
import com.xmut.mall.order.service.OrderComplaintCommunicationService;


@Service("orderComplaintCommunicationService")
public class OrderComplaintCommunicationServiceImpl extends ServiceImpl<OrderComplaintCommunicationDao, OrderComplaintCommunicationEntity> implements OrderComplaintCommunicationService {


    /**
     * 投诉过程中三个角色进行交流
     * @param dto
     * @return
     */
    @Override
    public RespBean communication(OrderComplaintCommunicationDto dto) {
        OrderComplaintCommunicationEntity entity = new OrderComplaintCommunicationEntity();
        BeanUtil.copyProperties(dto,entity);
        if (dto.getType().equals("manager")){
            entity.setOwner(CommunicationOwnerEnum.PLATFORM.name());
        }else if (dto.getType().equals("seller")){
            entity.setOwner(CommunicationOwnerEnum.STORE.name());
        }else if (dto.getType().equals("buyer")){
            entity.setOwner(CommunicationOwnerEnum.BUYER.name());
        }
        entity.setCreateTime(new Date());
        boolean save = this.save(entity);
        if (save){
            return RespBean.success("回复成功");
        }else {
            return RespBean.error("回复失败");
        }

    }
}